var app = getApp()
const util = require('../../../utils/util.js')
 Page({
  data: { 
    catlist: [],
    screenWidth: 0,
    screenHeight: 0,
    imgwidth: 0,
    imgheight: 0,
    url: app.globalData.url,
    configurl: app.globalData.configurl,
    type: "all",
    state: 0,
    search: ""
  },

  onPullDownRefresh:function(){
    wx.stopPullDownRefresh()
  },

  //转发跳转页面设置
  onLoad: function (options) {
    var _this = this;
    console.log(options);
    _this.setData({
      type:options.cattype,
      state:options.state,
      search:options.search == undefined?"":options.search
    });
    util.getCatConfig(app.globalData.configurl + "config/cats.json").then( res => {
      
      app.globalData.cats = res;
      _this.setData({
        catlist: res
      })
    })
    if (options.pageId) {
      wx.navigateTo({
        url: '/pages/cats/' + options.pageId + '/' + options.pageId,
      })
    }
  },
  //事件处理函数
  gotocatdetailed: function(e) {
    wx.navigateTo({
      url: '/pages/index/catdetailed/catdetailed?catinfo=' + JSON.stringify(e.currentTarget.dataset.item)
    })
  },
  //转发此页面的设置
  onShareAppMessage: function (ops) {
    if (ops.from === 'button') {
      // 来自页面内转发按钮
      console.log(ops.target)
    }
    return {
      path: 'pages/index/index',  // 路径，传递参数到指定页面。
      success: function (res) {
        // 转发成功
        console.log("转发成功:" + JSON.stringify(res));
      },
      fail: function (res) {
        // 转发失败
        console.log("转发失败:" + JSON.stringify(res));
      }
    }
  },

  // 搜索栏输入名字后页面跳转
  bindconfirmT: function (e) {
    console.log("e.detail.value");
    if(e.detail.value) {
    
    wx.navigateTo({
      url: '/pages/cats/' + e.detail.value + '/' + e.detail.value,
    })
  }
  }


})

